﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using EnvDTE;

using FanaticToy.Core;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.Shell;

namespace FanaticToy
{
    public partial class FanaticToyPackage
    {
        public void Init()
        {
            var dte = GetService(typeof(DTE)) as DTE;
            ThisSingleton.Init(dte);
        }
    }

    ///<summary>全局的单例。</summary>
    public static class ThisSingleton
    {
        public static ThisAddIn ThisAddIn { get; set; }

        public static void Init(DTE dte)
        {
            if (ThisAddIn == null)
            {
                ThisAddIn = new ThisAddIn(dte);


                var serviceColl = new ServiceCollection();
                serviceColl.AddSingleton(typeof(ThisAddIn), ThisAddIn);
                var provider = serviceColl.BuildServiceProvider();
                CommunityToolkit.Mvvm.DependencyInjection.Ioc.Default.ConfigureServices(provider);
            }
    
        }
    }
}
